package com.tjec.project.businessStandardLibrary.controller;

import com.tjec.common.enums.BusinessCategoryUser;
import com.tjec.common.enums.ErrCode;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.framework.web.domain.TreeSelectAndChildrenNum;
import com.tjec.project.system.domain.BmsMdBusinessCategory;
import com.tjec.project.system.service.IBmsMdBusinessCategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 业务标准库树接口
 *
 * @Author: VillWang
 * @Date: 2020/4/26 15:09
 */
@Api("业务标准库")
@RestController
@RequestMapping("/libraryTree/tree")
public class BmsStandardsLibraryTreeController extends BaseController {

    @Autowired
    private IBmsMdBusinessCategoryService bmsMdBusinessCategoryService;

    /**
     * @return com.tjec.framework.web.domain.AjaxResult
     * @describe 业务标准库 树
     * @params [businessCategory, tableName]
     * @author VillWang
     * @date 2020/4/26
     * @other
     */
   // @PreAuthorize("@ss.hasPermi('system:businessCategory:treeselect')")
    @GetMapping("/libraryTreeList")
    public AjaxResult libraryTreeList(BmsMdBusinessCategory businessCategory, BusinessCategoryUser tableName) {

        if (null == tableName) {
            return new AjaxResult(ErrCode.SYS_PARAMETER_EMPTY.getErrCode(), ErrCode.SYS_PARAMETER_EMPTY.getErrMsg());
        }
        List<BmsMdBusinessCategory> businessCategorys = bmsMdBusinessCategoryService.selectBusinessCategoryAndChildrenNumList(businessCategory, tableName.name());
        List<TreeSelectAndChildrenNum> list = bmsMdBusinessCategoryService.buildBusinessTreeSelectAndChildrenNum(businessCategorys, false);
        return AjaxResult.success(list);
    }
    /**
     * @return com.tjec.framework.web.domain.AjaxResult
     * @describe 业务标准库 树
     * @params [businessCategory, tableName]
     * @author VillWang
     * @date 2020/4/26
     * @other
     */
   // @PreAuthorize("@ss.hasPermi('system:businessCategory:treeselect')")
    @GetMapping("/libraryTreeListMore")
    public AjaxResult libraryTreeListMore(BmsMdBusinessCategory businessCategory, BusinessCategoryUser tableName) {

        if (null == tableName) {
            return new AjaxResult(ErrCode.SYS_PARAMETER_EMPTY.getErrCode(), ErrCode.SYS_PARAMETER_EMPTY.getErrMsg());
        }
        List<BmsMdBusinessCategory> businessCategorys = bmsMdBusinessCategoryService.selectBusinessCategorySelectOneToMore(businessCategory, tableName.name());
        List<TreeSelectAndChildrenNum> list = bmsMdBusinessCategoryService.buildBusinessTreeSelectAndChildrenNum(businessCategorys);
        return AjaxResult.success(list);
    }
}
